<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
if($_RQ['op']=='main'){
	$type=intval($_RQ['type'])?:1;
	if($_RQ['store_id']){
		$store_id = intval($_RQ['store_id']);
		$this->session('store_id',$store_id);
	}
	if(!$store_id){
		$store_id=$this->session('store_id');
	}
	$return['groups']=pdo_getall('jy_qiuyuyue_serve_group',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','title'),'','paixu desc,id desc');
	$return['pluginset']['searchkeyword']=$return['pluginset']['searchkeyword']?explode('|',$return['pluginset']['searchkeyword']):array('健康养护','水氧小气泡','脸部SPA','背部SPA');
	$return['params']=array('groupid'=>intval($_RQ['groupid']),'type'=>$type,'store_id'=>$store_id?:0);
	$return['list']=array();
	$return['sharedata']=array(
			'title'=>'项目列表',
			'desc'=>$basic['share_desc']?:'球场预定，在线预定足球场，羽毛球场！',
			'link'=>custom_url('jy_qiuyuyue/serverlist//fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>'1');
	$onestore=intval($_RQ['onestore']);
	if(trim($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
	if($_RQ['groupid']){
		$params['groupid']=intval($_RQ['groupid']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	if($onestore){
		$params['store_id']=intval($_RQ['store_id']);
	}
	$list=pdo_getslice('jy_qiuyuyue_serve',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$item){
			$item['ordernum']=pdo_count('jy_qiuyuyue_server_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$item['id']));
			//按点赞数排序作品
				$pindex = max(1, 0);
				$psize = 4;
				$members=pdo_getslice('jy_qiuyuyue_server_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$item['id']),array($pindex,$psize),$total,array('mid'),'','id desc');
				foreach($members as &$mv){
					$memberinfo=pdo_get('core_members',array('id'=>$mv['mid']),array('nickname','avatar'));
					$mv['nickname']=$memberinfo['nickname'];
					$mv['avatar']=$memberinfo['avatar'];
				}
				$item['members']=$members;	
	}
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	$return['post']=array();
	$return['list']=$list;
	exi($return);
}
